﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using RBOSS.Data;
using RBOSS.Business.CustomerModule;
using System.Data.Entity;
//using System.Data.Entity.Migrations;

namespace RBOSS.Business.VendorModule
{
    public class VendorProfile_sys
    {
        // int RoleId; string FirstName; string LastName; string Email; string Password; string PhoneNo; string City; string Province; string Country; string PostalCode;
        RBOSSEntities rb = new RBOSSEntities();
        public int BankId { get; set; }
        public int UserId { get; set; }
        public string AccountNumber { get; set; }
        public string AccountType { get; set; }
        public string BankName { get; set; }
        public string BankBranch { get; set; }


        public int RoleId { get; set; }
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public string Email { get; set; }
        public string Password { get; set; }
        public string PhoneNo { get; set; }
        public string City { get; set; }
        public string Province { get; set; }
        public string Country { get; set; }
        public string PostalCode { get; set; }

        public VendorProfile_sys getvendordata(string email)
        {
            VendorProfile_sys v = new VendorProfile_sys();
            CustomerSubSystem s = new CustomerSubSystem();
            //VendorProfile_sys v = new VendorProfile_sys();
            int userid = s.GetCustomerId(email);
            var query = rb.Users.Where(e => e.UserId == userid).FirstOrDefault();
            if (query != null)
            {
                v.UserId = query.UserId;
                v.RoleId = query.RoleId;
                v.Province = query.Province;
                v.PostalCode = query.PostalCode;
                v.PhoneNo = query.PhoneNo;
                v.Password = query.Password;
                v.LastName = query.LastName;
                v.FirstName = query.FirstName;
                v.Email = query.Email;
                v.Country = query.Country;
                v.City = query.City;

                // bank details

                var query2 = rb.BankDetails.Where(e => e.UserId == query.UserId).FirstOrDefault();
                if (query2 != null)
                {
                    v.BankId = query2.BankId;
                    v.BankName = query2.BankName;
                    v.BankBranch = query2.BankBranch;
                    v.AccountType = query2.AccountType;
                    v.AccountNumber = query2.AccountNumber;
                }
            }
            return v;

        }
        public VendorProfile_sys getbankdetails(string email)
        {
            VendorProfile_sys v = new VendorProfile_sys();
            CustomerSubSystem s = new CustomerSubSystem();
            //VendorProfile_sys v = new VendorProfile_sys();
            int userid = s.GetCustomerId(email);
            var query2 = rb.BankDetails.Where(e => e.UserId == userid).FirstOrDefault();
                if (query2 != null)
                {
                    v.BankId = query2.BankId;
                    v.BankName = query2.BankName;
                    v.BankBranch = query2.BankBranch;
                    v.AccountType = query2.AccountType;
                    v.AccountNumber = query2.AccountNumber;
                    return v;
                }
                return null;
        }

        public void updatevendorinfo(string userEmail, string firstName, string lastName, string phoneNo, string city, string provience, string country, string postalCode)
        {
            CustomerSubSystem s = new CustomerSubSystem();
            int userid = s.GetCustomerId(userEmail);
            var query = rb.Users.Where(e => e.UserId == userid).FirstOrDefault();

            query.Email = userEmail;

            query.Country = country;
            query.City = city;
            query.FirstName = firstName;
            query.LastName = lastName;
            query.PhoneNo = phoneNo;
            query.PostalCode = postalCode;
            query.Province = provience;

            rb.SaveChanges();
        }



    }
}
